package com.tzx.fluttermixedapplication.activity

import android.app.Activity
import android.os.Bundle
import android.util.Log
import android.widget.Button
import android.widget.LinearLayout
import com.tzx.fluttermixedapplication.R
import io.flutter.embedding.android.FlutterActivity
import io.flutter.plugin.common.MethodChannel

class SecondActivity : Activity() {
    private lateinit var container: LinearLayout
    private lateinit var button: Button
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_second_layout)
        container = findViewById(R.id.root)
        button = findViewById(R.id.button)
        button.setOnClickListener {
            BaseFlutterFragmentActivity.GlobalFlutterEngine?.let {
                MethodChannel(
                    it.dartExecutor.binaryMessenger,
                    BaseFlutterFragmentActivity.FLUTTER_CHANNEL
                )
                    .invokeMethod(
                        BaseFlutterFragmentActivity.FLUTTER_METHOD,
                        listOf("this page is second activity"),
                        object : MethodChannel.Result {
                            override fun success(result: Any?) {
                                Log.d("SecondActivity", "计算结果为 = $result")
                            }

                            override fun error(
                                errorCode: String,
                                errorMessage: String?,
                                errorDetails: Any?
                            ) {
                                Log.d("MyFlutterActivity", "出错了：$errorCode, $errorMessage, $errorDetails")
                            }

                            override fun notImplemented() {
                                Log.d("SecondActivity", "notImplemented")
                            }
                        })
            }
        }
    }
}
